package LeetCode.month03.day84;

/**
 * @author 16778
 * @date 2025/10/24 8:18
 * @description
 */
public class No2048 {
    public int nextBeautifulNumber(int n) {
        for (int i = n+1;; i++) {
            if(isBalance(i)) return i;
        }
    }

    public boolean isBalance(int n){
        int[] count = new int[10];
        while(n>0){
            count[n%10]++;
            if(count[n%10]>n%10) return false;
            n/=10;
        }
        for (int i = 0; i < 10; i++) {
            if(count[i]!=0&&count[i]!=i) return false;
        }
        return true;
    }
}
